<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <link rel="stylesheet" type="text/css" href="__STATIC__/index/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="__STATIC__/index/css/LArea.min.css"/>
    <script type="text/javascript" src="__STATIC__/index/js/rem.js"></script>
    <title>个人资料</title>
</head>
<body class="whiteBg">
<div class="edit">
    <!--编辑头像-->
    <div class="edit_avatar clear whiteBg">
        <p class="fl super-text smoth bold">头像</p>
        <form class="fr">
            <div class="default_img">
                <img id="fileImg" class="auto-img" src="{$user.headimg ?: ''}"/>
            </div>
            <input type="hidden" name="headimg" value="" id="chooseImg"/>
            <i class="arrow"></i>
        </form>
    </div>
    <!--输入姓名 选择城市-->
    <div class="edit_name whiteBg">
        <div class="form_msg smoth super-text">
            <span class="bold">姓名</span>
            <input type="text" name="nickname" value="{$user.nickname ?: ''}" placeholder="请输入姓名"/>
        </div>
        <div class="form_msg smoth super-text">
            <span class="bold">所在地区</span>
            <input id="ipt" type="text" name="area" value="{$user.area ?: ''}" placeholder="请选择所在地区" readonly=""/>
            <input type="hidden" id="value2"/>
            <input type="hidden" id="default">
            <i class="form_arrow"></i>
        </div>
        <div class="save_btn">
            <button>保存</button>
        </div>
    </div>
</div>
<script type="text/javascript" src="__STATIC__/index/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="__STATIC__/index/js/LArea.js"></script>
<script type="text/javascript" src="__STATIC__/index/js/LAreaData1.js"></script>
<script type="text/javascript" src="__STATIC__/index/js/LAreaData2.js"></script>
<script type="text/javascript" src="__STATIC__/index/js/layer/mobile/layer.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript">

    wx.config({$jsSign|raw});
    wx.ready(function () {
        $('.default_img').click(function () {
            wx.chooseImage({
                count: 1, // 默认9
                sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                success: function (res) {
                    localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                    $('#fileImg').attr('src', localIds);
                    wx.uploadImage({
                        localId: localIds.toString(), // 需要上传的图片的本地ID，由chooseImage接口获得
                        isShowProgressTips: 1, // 默认为1，显示进度提示
                        success: function (res) {
                            serverId = res.serverId; // 返回图片的服务器端ID
                            $("input[name='headimg']").val(serverId);
                        }
                    });
                }
            });
        });
    });

    //匹配iOS 失去焦点
    $("#ipt").focus(function () {
        document.activeElement.blur();
    });
    var area = new LArea();
    area.init({
        'trigger': '#ipt',
        'valueTo': '#value2',
        'defaultval': '#default',
        'keys': {
            id: 'value',
            name: 'text'
        },
        'type': 2,
        'data': [provs_data, citys_data, dists_data]
    });
    area.value = [18, 0, 3];

    //点击保存返回
    $('.save_btn button').on('click', function () {
        var nickname = $('input[name="nickname"]').val();
        var headimg = $('input[name="headimg"]').val();
        var area = $('input[name="area"]').val();
        if (nickname == '') {
            layer.open({content: '姓名不能为空', skin: 'msg', time: 2})
        } else {
            $.ajax({
                url: "",
                type: "post",
                data: {nickname:nickname,headimg:headimg,area:area},
                success: function (res) {
                    if (res=='ok'){
                        layer.open({
                            content: '保存成功',
                            skin: 'msg',
                            time: 2,
                            end: function () {
                                window.location.href = 'javascript:history.back()'
                            }
                        })
                    }
                }
            })
        }

    })


    // function utf16toEntities(str) {
    //     var patt=/[\ud800-\udbff][\udc00-\udfff]/g; // 检测utf16字符正则
    //     str = str.replace(patt, function(char){
    //         var H, L, code;
    //         if (char.length===2) {
    //             H = char.charCodeAt(0); // 取出高位
    //             L = char.charCodeAt(1); // 取出低位
    //             code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00; // 转换算法
    //             return "&#" + code + ";";
    //         } else {
    //             return char;
    //         }
    //     });
    //     alert(str);
    //     alert(uncodeUtf16(str));
    //     return str;
    // }
    //
    // function uncodeUtf16(str){
    //     var reg = /\&#.*?;/g;
    //     var result = str.replace(reg,function(char){
    //         var H,L,code;
    //         if(char.length == 9 ){
    //             code = parseInt(char.match(/[0-9]+/g));
    //             H = Math.floor((code-0x10000) / 0x400)+0xD800;
    //             L = (code - 0x10000) % 0x400 + 0xDC00;
    //             return unescape("%u"+H.toString(16)+"%u"+L.toString(16));
    //         }else{
    //             return char;
    //         }
    //     });
    //     return result;
    // }
</script>
</body>
</html>